home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / datescrn.arc / DATE.C < prev    next >
Encoding:
Text File  |  1985-12-12  |  2.5 KB  |  90 lines

  1. /*  date()  */
  2. /*  This function performs a system function call to get the system */
  3. /*  date, and returns a formattted string via the pointer `ptr'. */
  4.  
  5. date(ptr, mode)
  6. char *ptr;
  7. int  mode;
  8. #define GET_DATE  0x2A
  9. #define byte char
  10. #define ONE   1
  11. #define TWO   2
  12. #define THREE 3
  13. #define FOUR  4
  14. #define FIVE  5
  15. #define SIX   6
  16. #define SEVEN 7
  17.  
  18. {
  19.  
  20.      int hold_yr;
  21.      struct  XREG {short ax, bx, cx, dx, si, di;};
  22.      struct  HREG {byte  al, ah, bl, bh, cl, ch, dl, dh;};
  23.      union   REGS {
  24.                struct  XREG x;
  25.                struct  HREG h;
  26.      } inregs, outregs;
  27.  
  28.      struct  dt  {
  29.                short month;
  30.                short day;
  31.                short year;
  32.                char  *mname;
  33.                char  *lname;
  34.      };
  35.  
  36.      struct dt pdate;
  37.      
  38.      static char *name[] = {
  39.           "invalid",
  40.           "Jan", "Feb", "Mar", "Apr", "May", "Jun",        
  41.           "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
  42.      };
  43.      
  44.      static char *name2[] = {
  45.           "invalid",
  46.           "January", "February", "March", "April", "May", "June",        
  47.           "July", "August", "September", "October", "November", "December"
  48.      };
  49.      
  50.      inregs.h.ah = GET_DATE;
  51.      inregs.h.al = 0;
  52.      intdos(&inregs, &outregs);
  53.      
  54.      pdate.day   = outregs.h.dl;
  55.      pdate.month = outregs.h.dh;
  56.      pdate.year  = outregs.x.cx;
  57.      pdate.mname = name[pdate.month];
  58.      pdate.lname = name2[pdate.month];
  59.  
  60.      if (pdate.year >= 2000)
  61.           hold_yr = pdate.year - 2000;
  62.      else hold_yr = pdate.year - 1900;
  63.  
  64.      switch (mode) {
  65.      case ONE:
  66.           sprintf(ptr, "%02d%02d%02d", hold_yr, pdate.month, pdate.day);
  67.           break;
  68.      case TWO:
  69.           sprintf(ptr, "%02d/%02d/%02d", pdate.month, pdate.day, hold_yr);
  70.           break;
  71.      case THREE:
  72.           sprintf(ptr, "%02d-%02d-%02d", pdate.month, pdate.day, hold_yr);
  73.           break;
  74.      case FOUR:
  75.           sprintf(ptr, "%s %02d, %d", pdate.mname, pdate.day, pdate.year);
  76.           break;
  77.      case FIVE:
  78.           sprintf(ptr, "%s %02d, %d", pdate.lname, pdate.day, pdate.year);
  79.           break;
  80.      case SIX:
  81.           sprintf(ptr, "%02d %s %02d", pdate.day, pdate.mname, hold_yr);
  82.           break;
  83.      case SEVEN:
  84.           sprintf(ptr, "%02d %s %02d", pdate.day, pdate.mname, pdate.year);
  85.           break;
  86.      default:
  87.           break;
  88.      }   
  89. }
  90.